﻿using SwenAssigment.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    ClientScriptManager cs = Page.ClientScript;
                    cs.RegisterStartupScript(this.GetType(), "PopupScript", "alert('Only poeple with no account can access');window.location.href = 'default.aspx';", true);

                }
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            String result = JcUser.CreateAccount(Convert.ToInt32(TextBox1.Text), TextBox2.Text, TextBox3.Text, TextBox7.Text, TextBox4.Text, SecureFunction.hashvalue(TextBox5.Text), DropDownList1.SelectedValue.ToString());
            if (result == "Staff Information Error")
            {
                result = "The staff information you provide is invaild";
            }
            else if (result == "User Name Exist")
            {
                result = "The user name cannot be use";
            }
            else if (result == "Have request before")
            {
                result = "The staff have have a account or have request before";
            }
            else
            {
                result = "Request Sended!, Ref ID: " + result;
            }
            // Response.Write("<script>window.alert('" + result + "')</script>");
            ClientScriptManager cs = Page.ClientScript;
            cs.RegisterStartupScript(this.GetType(), "PopupScript", "alert('" + result + "');window.location.href = 'default.aspx';", true);
        }
    }
}